//【模板】负环:https://www.luogu.com.cn/problem/P3385


//bf算法：
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int N = 2e3+10,INF = 0x3f3f3f3f;

vector<pair<int,int>> edges[N];
int T;
int dist[N];
int n,m;

bool bf()
{
    bool flag = false;

    memset(dist,0x3f,sizeof dist);
    dist[1] = 0;
    for(int i = 1; i <= n; i++)
    {
        flag = false;
        for(int j = 1; j <= n; j++)
        {
            if(dist[j] == INF)continue;
            for(auto& e : edges[j])
            {
                int v = e.first,w = e.second;
                if(dist[j] + w < dist[v])
                {
                    flag = true;
                    dist[v] = dist[j] + w;

                }
            } 
        }
        if(flag == false)return false;
    }

    return flag;
}

int main()
{
    cin >> T;
    while(T--)
    {
        for(int i = 0; i < n; i++)
        edges[i].clear();
        cin >> n >> m;

        for(int j = 0; j < m; j++)
        {
            int u,v,w;
            cin >> u >> v >> w;
            edges[u].push_back({v,w});
            if(w >= 0)
            edges[v].push_back({u,w});
        }
        if(bf())cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}